Imports System.Xml
Imports System.Xml.Linq
Imports System.Linq

Public Class FrmInlogscherm

    Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogin.Click

        'Instantiate a connection.
        Dim str1 As String = My.Settings.Docregdata2ConnectionString
        Dim cnn1 As SqlClient.SqlConnection = New SqlClient.SqlConnection(str1)
        cnn1.Open()

        'Declare command to validate MemberID and password.
        Dim cmd1 As SqlClient.SqlCommand = cnn1.CreateCommand
        cmd1.CommandType = CommandType.StoredProcedure
        cmd1.CommandText = "Goedgekeurde_gebruiker"

        'prm1 pakt de return value van de stored procedure.
        Dim prm1 As SqlClient.SqlParameter = cmd1.Parameters.Add("@OK", SqlDbType.Int)
        prm1.Direction = ParameterDirection.ReturnValue

        cmd1.Parameters.AddWithValue("@gebruikersnaam", Me.GebruikersnaamComboBox.Text)
        cmd1.Parameters.AddWithValue("@paswoord", Me.txtwachtwoord.Text)

        'Execute the command.
        cmd1.ExecuteNonQuery()

        'Accept the return value:
        '1 if valid
        '0 otherwise
        Dim count As Byte = CByte(cmd1.Parameters("@OK").Value)
        If count = 1 Then
            Me.Visible = False
            My.Forms.FrmHoofdmenu.Visible = True
        Else
            MsgBox("Onjuiste gebruikersnaam of wachtwoord. Probeer opnieuw!")
        End If

        cnn1.Close()

    End Sub

    Private Sub FrmInlogscherm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DocRegData2DataSet.Werken' table. You can move, or remove it, as needed.
        Me.WerkenTableAdapter.Fill(Me.DocRegData2DataSet.Werken)
        'TODO: This line of code loads data into the 'DocRegData2DataSet.Gebruikers' table. You can move, or remove it, as needed.
        Me.GebruikersTableAdapter.Fill(Me.DocRegData2DataSet.Gebruikers)

        SelectieDirectory()

    End Sub


    Public Sub SelectieDirectory()

        'Selecteren van projectdirectory uit ProjectDirectorysxml
        Dim Xprojectdir As XDocument
        'Xprojectdir = XDocument.Load("C:\Documents and settings\Hanzie\My Documents\Projectdirectorys.xml")
        Xprojectdir = XDocument.Load(System.AppDomain.CurrentDomain.BaseDirectory & "\Projectdirectorys.xml")

        Dim x = From Dir In Xprojectdir...<Project> _
                 Where Dir.<Werknummer>.Value.Contains(Me.CmbWerknummer.Text) _
              Select Dir.<ProjectDirectory>.Value

        For Each dr As String In x
            txtProjectdir.Text = dr.ToString

        Next

    End Sub

    Private Sub CmbWerknummer_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbWerknummer.SelectedValueChanged

        Me.SelectieDirectory()

        End Sub



End Class